<?php

namespace App\Http\Controllers\admin;

use App\Dao\CategoryDao;
use App\Services\Code;

class CategorysController extends BaseController
{
    public function categorys()
    {
        if(getIsHasPage()){
            return Code::message('',200,CategoryDao::categorys(request()->all()));
        }
        return view('admin.categorys.categorys');
    }

    public function add()
    {
        if (isPost()){
            $params = request()->all();
            CategoryDao::add($params);
            return  Code::message('',200);
        }
        return view('admin.categorys.adds');
    }

    public function edit(){
        if(isPost()){
            $params = request()->all();
            CategoryDao::edit($params);
            return Code::message('修改成功',200);
        }
        $info = CategoryDao::category_info(['category_id'=>request('category_id')]);
        return view('admin.categorys.edit',[
            'info'=>$info
        ]);
    }

    public function delete(): array
    {
        $params = request()->all();
        CategoryDao::delete($params);
        return Code::message('删除成功',200);
    }
}
